package com.erclab.internal.xpresso.formelements;

import com.erclab.internal.xpresso.exceptions.FormException;
import com.erclab.internal.xpresso.forms.Form;

public class ListDropDown extends FormElement {

	@Override
	public boolean isModifiable() {
		return true;
	}

	@Override
	public void loadLookupValues(Form theForm) throws FormException {
		// Nothing to do.

	}

	@Override
	public String toHTML(Form theForm) {
		StringBuffer sb = new StringBuffer();
		sb.append("<SELECT name=\"Field");
		sb.append(this.idFormElement);
		sb.append("\"");
		sb.append(" id=\"" + this.destinationColumn + "\" onChange=\"formElementChanged(this)\">");
		String[] display = this.parameters.split(", ");
		for (int i =0; i < display.length; i++){
			sb.append("<OPTION VALUE=" + '"' + display[i] + '"');
			if(originalValue != null && originalValue.equalsIgnoreCase(display[i])){
				sb.append(" selected>" + display[i] + "</OTPION>");
			} else {
				sb.append(">" + display[i] + "</OTPION>\n");
			}
		}
		sb.append("</SELECT>");
		return sb.toString();
	}

}
